package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.StickBean;
import com.project.bean.UserBean;
import com.project.service.IStickService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("stick")
public class StickController {
    @Autowired
    private IStickService service;
    @RequestMapping("findByItem")
    public IPage<StickBean> findByItem(Integer pageNO, Integer channelId , String title, String name,
                                       LocalDate startDate, LocalDate endDate){
        return service.findByItem(pageNO, channelId, title, name, startDate, endDate);
    }
    @RequestMapping("add")
    public String hairAdd(StickBean stick, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        stick.setUserId(user.getUserId());
        service.add(stick);
        return "ok";
    }
    @RequestMapping("findById")
    public StickBean findById(Integer stickId){
        return service.findById(stickId);
    }
}
